<?php
class Distrito extends AppModel {
    var $name = 'Distrito';
	
    function generateCodigo(){
		$result = $this->query('select 
									COALESCE(cast(max(d.codigo) as integer)+1,1) as "Distrito__codigo" 
								from maestros.distritos d 
								where d.activo = true');
		$result = $result[0];
		return str_repeat('0',6-strlen($result['Distrito']['codigo'])).$result['Distrito']['codigo'];			
	}
}
?>